package com.shqcjd.siemensglass.adapter;

import android.content.Context;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.View;
import android.widget.RelativeLayout;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.gcssloop.widget.RCImageView;
import com.shqcjd.siemensglass.R;
import com.shqcjd.siemensglass.bean.ImageBean;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 图片列表
 * Created by sy on 2018/9/19.
 */

public class ImageAdapter extends BaseQuickAdapter<ImageBean,ImageAdapter.ViewHolder> {
    private Context context;
    public int currentPos = -2;


    public ImageAdapter(@Nullable List<ImageBean> data, Context context) {
        super(R.layout.item_image_layout, data);
        this.context = context;
    }

    @Override
    protected void convert(final ViewHolder helper, ImageBean item) {
        RequestOptions options = new RequestOptions();
        options.placeholder(R.mipmap.ic_small_loading);//图片加载出来前，显示的图片
        Glide.with(context)
                .load(item.url)
                .apply(options)
                .into(helper.riv_image);

        if (item.isShow) {
            helper.rl_hazy_view.setVisibility(View.GONE);
        } else {
            helper.rl_hazy_view.setVisibility(View.VISIBLE);
        }

        helper.rl_item_image_bg.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if(hasFocus){
                    currentPos = helper.getPosition();
                }
            }
        });
    }


    class ViewHolder extends BaseViewHolder {
        @BindView(R.id.riv_image)
        RCImageView riv_image;
        @BindView(R.id.rl_hazy_view)
        RelativeLayout rl_hazy_view;
        @BindView(R.id.rl_item_image_bg)
        RelativeLayout rl_item_image_bg;

        public ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
